<?php
session_start();
if (isset($_SESSION["username"])) {
?>
  <?php require_once('common/header.php'); ?>
  <!--页面主要内容-->
  <main class="lyear-layout-content">
    <div class="container-fluid">
      <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-toolbar clearfix">
             
            </div>
            <div class="card-body">
              <div class="table-responsive">
                <form name="form1" id="form1" method="post" action="controller/deleteall.php">
                  <table class="table table-bordered">
                    <?php
                    $proxy_id = $_GET['proxy_id'];
                    include_once("../untils/conn.php");
                    mysqli_query($con, "set names utf8");
                    if ($con) {
                      if ($db) {
                        //获取数据总行数
                        $sql = "SELECT * FROM proxy WHERE proxy_upid = '$proxy_id'";
                        $data = mysqli_query($con, $sql);
                        $maxrows = mysqli_num_rows($data);
                        //计算总页数
                        $page_size = 10;  //每页显示数
                        if ($maxrows % $page_size == 0) {
                          $maxpage = (int)($maxrows / $page_size);
                        } else {
                          $maxpage = (int)($maxrows / $page_size) + 1;
                        }
                        //获取当前页
                        if (isset($_GET['curpage'])) {
                          $page = $_GET['curpage'];
                        } else {
                          $page = 1;
                        }
                        //分段取出数据
                        $start = $page_size * ($page - 1);
                        $get_sql = "SELECT * FROM proxy WHERE proxy_upid = '$proxy_id' LIMIT $start,$page_size";
                        //得到数据显示
                        $data = mysqli_query($con, $get_sql);
                    ?>
                    <?php 
                    $proxy_upid = $row["proxy_upid"]
                    
                    ?>
                        <thead>
                          <tr>
                            <th>代理ID</th>
                            <th>代理账号</th>
                            <th>代理名称</th>
                            <th>手机号码</th>
                            <th>代理余额</th>
                            <th>代理实名</th>
                            <th>身份证号</th>
                            <th>上级代理</th>
                            <th>支付宝</th>
                            <th>支付宝账号</th>
                            <th>银行卡</th>
                            <th>银行卡号</th>
                            <!--<th>邀请码</th>-->
                            <th>账号状态</th>
                            <th>实名状态</th>
                            <th>类型</th>
                            
                            <th>操作</th>
                          </tr>
                        </thead>
                        <tbody>
                        <?php
                        while ($row = mysqli_fetch_array($data)) {
                            // 获取上级代理名称
                            $proxy_upid = $row["proxy_upid"];
                            if ($proxy_upid != "") {
                                $get_up_proxy_name_sql = "SELECT proxy_name FROM proxy WHERE proxy_id = $proxy_upid";
                                $get_up_proxy_name_result = mysqli_query($con, $get_up_proxy_name_sql);
                                $up_proxy_name = mysqli_fetch_array($get_up_proxy_name_result)["proxy_name"];
                            } else {
                                $up_proxy_name = "直属平台";
                            }
                        ?>
                            <tr>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_id"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_acc"] ?>
                                    
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_name"] ?>
                                </td>
                                 <td style="width:5%;">
                                    <?php echo $row["proxy_phone"] ?>
                                </td>
                                 <td style="width:5%;">
                                    ￥<?php echo $row["proxy_balance"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_rename"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_uid"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $up_proxy_name ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_alipay_name"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_alipay"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_yihname"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_yhnum"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_intcode"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php
                                    if ($row["proxy_sta"] == 1) {
                                        echo '<span class="label label-success">账号正常</span>';
                                    } else {
                                        echo '<span class="label label-danger">封禁状态</span>';
                                    }
                                    ?>
                                </td>
                                <td style="width:5%;">
                                    <?php
                                    if ($row["proxy_rename_sta"] == 1) {
                                        echo '<span class="label label-info">已实名</span>';
                                    } else {
                                        echo '<span class="label label-info">未实名</span>';
                                    }
                                    ?>
                                </td>
                                <td style="width:5%;">
                                    <?php
                                    if ($row["proxy_type"] == 0) {
                                        echo '<span class="label label-info">个人</span>';
                                    } else {
                                        echo '<span class="label label-info">企业</span>';
                                    }
                                    ?>
                                </td>
                                <td style="width:15%;">
                                    <?php if($row["proxy_sta"] == 1) {?>
                                        <a href="controller/Doproxy_sta.php?proxy_id=<?php echo $row["proxy_id"] ?>" class="btn btn-danger btn-sm" target="_blank">封禁账号</a>
                                    <?php } else { ?>
                                        <a href="controller/Doproxy_sta.php?proxy_id=<?php echo $row["proxy_id"] ?>" class="btn btn-success btn-sm" target="_blank">解封账号</a>
                                    <?php } ?>
                                    <!--<a href="" onclick=" return del()" class="btn btn-warning btn-sm">下级代理</a>-->
                                </td>
                            </tr>
                        <?php
                        }
                        ?>
                    </tbody>
                        <tfoot>
                          <tr>
                            <td colspan="12" style="text-align: right;">
                          <?php
                          echo "<p>共 $maxpage 页&nbsp;&nbsp;";
                          echo "每页 $page_size 项&nbsp;&nbsp;";
                          //设置上一页
                          if ($page > 1) {
                            $prepage = $page - 1;
                            echo "<a href='?curpage=$prepage'>上一页</a>&nbsp;&nbsp;";
                          }
                          //设置下一页
                          if ($page < $maxpage) {
                            $nextpage = $page + 1;
                            echo "<a href='?curpage=$nextpage'>下一页</a>&nbsp;&nbsp;";
                          }
                          echo "&nbsp;&nbsp;第 $page 页</p>";
                        }
                      }
                          ?>
                            </td>
                          </tr>
                        </tfoot>
                  </table>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    </div>
  </main>
  <!--End 页面主要内容-->
  <?php require_once('common/footer.php'); ?>
<?php
} else {
  echo "<script>alert('您尚未登录，没有权限访问该页面');location.href='login.php';</script>";
}
